package ref;

/**
 * @author Mark
 * @date 2020/5/24 22:29
 * @description 类初始化
 */
public class ClassInit {

    static {
        System.out.println("main类被加载");
    }

    public static void main(String[] args) throws ClassNotFoundException {
//        // 主动引用
//        Son son = new Son();

        // 主动引用
//        Class.forName("ref.Son");

//        System.out.println("Son.num1 = " + Son.num1);

//        Son[] sons = new Son[6];

        System.out.println("Son.NUM = " + Son.NUM);
    }
}

class Father {

    static int num1 = 2;

    static {
        System.out.println("父类被加载");
    }
}

class Son extends Father {

    static {
        System.out.println("子类被加载");
        num = 300;
    }

    private static int num = 100;
    public static final int NUM = 100;
}